/**
 * Created by 2kid.
 * User: onwer
 * Date: 12-3-30
 * Time: 下午11:35
 */

var waterFall={
    coulun:4,
    line:10,
    alllinele:[],
    allimg:['http://cued.xunlei.com/demos/publ/img/P_000.jpg'],
    curimg:0,
    createlist:function(i){
        var tmpdiv=document.createElement('div');
            tmpdiv.className='list list'+i;
            this.appendele(tmpdiv,this.createsigle());
            return tmpdiv;
    },
    getimgsrc:function(){
        var cur='';
        if(this.curimg>=100){
            cur= this.curimg++;
        }else if(this.curimg>=10){
            cur= '0'+this.curimg++;
        }else{
            cur= '00'+this.curimg++;
        }
        return 'http://cued.xunlei.com/demos/publ/img/P_'+cur+'.jpg';

    },
    createsigle:function(){
        var tmpsigle=document.createElement('p');
            tmpsigle.innerHTML='<img src="'+this.getimgsrc()+'" alt=""><em><strong>'+this.curimg+'</strong> <span></span></em>';
            return tmpsigle;
    },
    appendele:function(ele,aele){
        ele.appendChild(aele);
    },
    isScrollbot:function(){
        var lineH=this.alllinele[0].scrollHeight;
//        for(var i=1;i<this.coulun;i++){
//            lineH=Math.min(lineH,this.alllinele[i].scrollHeight);
//
//        }
               var doc=document,docElement=document.documentElement,
         sct= Math.max(docElement['scrollTop'], doc.body['scrollTop']  ),

            scrollH=docElement.scrollTop+doc.body.scrollTop;

       return docElement.scrollHeight==docElement.clientHeight+sct;

    },
    init:function(){
        var _this=this;
        this.ocontent=document.getElementById('content');

        for(var i=0;i<this.coulun;i++){
            this.alllinele[i]=this.createlist(i);
            this.appendele(this.ocontent,this.alllinele[i]);
        }
        for(i=1;i<this.line;i++){
            for(var j=0;j<this.coulun;j++){
                this.appendele(this.alllinele[j],this.createsigle());
            }
        }

        window.onscroll=function(){
            if(_this.isScrollbot()){
                for(var j=0;j<_this.coulun;j++){
                    _this.appendele(_this.alllinele[j],_this.createsigle());
                }
            }
        }
    }
};

window.onload=function(){
    waterFall.init();
}
